
<template>
  <div>
    <MyHead title="添加OFFER "></MyHead>
    <div class="form">
      <van-form ref="form">
        <van-field
          v-model="form.name"
          name="name"
          label="OFFER标题"
          placeholder="OFFER标题"
          :rules="[{ required: true, message: '请填写' }]"
          center
          clearable
          required
        />
        <van-field
          v-model="form.company"
          name="company"
          label="面试公司"
          placeholder="面试公司"
          :rules="[{ required: true, message: '请填写' }]"
          center
          clearable
          required
        />
        <van-field
          v-model="form.salary"
          name="salary"
          label="入职薪资"
          placeholder="入职薪资"
          :rules="[{ required: true, message: '请填写' }]"
          center
          clearable
          required
        />
        <van-field
          v-model="form.tips"
          name="tips"
          label="入职提醒"
          placeholder="入职提醒"
          :rules="[{ required: true, message: '请填写' }]"
          center
          clearable
          required
        />
        <van-field
          readonly
          clickable
          name="time"
          :value="form.time"
          label="入职时间"
          placeholder="入职时间"
          @click="showPicker = true"
          required
          :rules="[{ required: true, message: '请选择' }]"
        />
        <van-calendar
          title="选择面试时间"
          :min-date="minDate"
          v-model="showPicker"
          @confirm="onConfirm"
        />
        <UploadFile @getfilepath="setDescPath">
          <van-field
            readonly
            clickable
            name="desc"
            label="OFFER图片"
            placeholder="OFFER图片"
          />
          <div v-if="form.desc">
            <img
              :src="form.desc.replace(/public/, baseURL)"
              alt=""
              class="desc"
            />
          </div>
        </UploadFile>
        <div class="btns" style="margin: 15px">
          <van-button
            @click="todoAddOFFERData"
            native-type="button"
            block
            type="primary"
            >添加OFFER <van-icon name="add-o"
          /></van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>
  
  <script>
import { todoAddOffer } from "@/api/api";
export default {
  data() {
    return {
      form: {},
      showPicker: false,
      minDate: new Date(2020, 0, 1),
    };
  },
  methods: {
    todoAddOFFERData() {
      this.$refs.form
        .validate()
        .then(async (valid) => {
          console.log(this.form);
          let res = await todoAddOffer(this.form);
          if (res.code == 200) {
            this.ShowSuccess("添加成功");
            this.$nextTick(() => {
              this.$router.go(-1);
            });
          }
        })
        .catch((err) => {
          this.ShowError("校验失败");
        });
    },
    setDescPath(path) {
      this.$set(this.form, "desc", path);
    },
    onConfirm(date) {
      this.showPicker = false;
      this.$set(this.form, "time", this.formatDate(date));
    },
  },
};
</script>
  
<style lang="scss" scoped>
.desc {
  width: 100%;
  margin-top: 20px;
  height: 230px;
  border-radius: 10px;
  padding: 20px;
}
</style>
  